using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Configuration;
using PCSComUtils.DataAccess;
using PCSComUtils.PCSExc;
using PCSComUtils.Common;
using System.Runtime.InteropServices;

namespace PCSComSale.Order.DS
{
	[Guid("4EE28776-E409-480d-A0E6-6F393FAEDB01")]
	public class SO_PackListMasterDS 
	{
		public SO_PackListMasterDS()
		{
		}
		private const string THIS = "PCSComSale.Order.DS.SO_PackListMasterDS";

	
		//**************************************************************************              
		///    <Description>
		///       This method uses to add data to SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///        SO_PackListMasterVO       
		///    </Inputs>
		///    <Outputs>
		///       newly inserted primarkey value
		///    </Outputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************

		public void Add(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";
			 
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS =null;
			try
			{
				SO_PackListMasterVO objObject = (SO_PackListMasterVO) pobjObjectVO;
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand("", oconPCS);
				
				strSql=	"INSERT INTO SO_PackListMaster("
				+ SO_PackListMasterTable.PACKLISTNO_FLD + ","
				+ SO_PackListMasterTable.PACKEDDATETIME_FLD + ","
				+ SO_PackListMasterTable.STATUS_FLD + ","
				+ SO_PackListMasterTable.SHIPPED_FLD + ","
				+ SO_PackListMasterTable.SHIPDATE_FLD + ","
				+ SO_PackListMasterTable.CARRIERID_FLD + ","
				+ SO_PackListMasterTable.WEIGHT_FLD + ","
				+ SO_PackListMasterTable.BOL_FLD + ","
				+ SO_PackListMasterTable.CONFIRMPACKDATE_FLD + ","
				+ SO_PackListMasterTable.EMPLOYEEID_FLD + ","
				+ SO_PackListMasterTable.UNITOFMEASUREID_FLD + ")"
				+ "VALUES(?,?,?,?,?,?,?,?,?,?,?)";

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.PACKLISTNO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[SO_PackListMasterTable.PACKLISTNO_FLD].Value = objObject.PackListNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.PACKEDDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[SO_PackListMasterTable.PACKEDDATETIME_FLD].Value = objObject.PackedDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.STATUS_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[SO_PackListMasterTable.STATUS_FLD].Value = objObject.Status;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.SHIPPED_FLD, OleDbType.Boolean));
				ocmdPCS.Parameters[SO_PackListMasterTable.SHIPPED_FLD].Value = objObject.Shipped;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.SHIPDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[SO_PackListMasterTable.SHIPDATE_FLD].Value = objObject.ShipDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.CARRIERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListMasterTable.CARRIERID_FLD].Value = objObject.CarrierID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.WEIGHT_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[SO_PackListMasterTable.WEIGHT_FLD].Value = objObject.Weight;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.BOL_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[SO_PackListMasterTable.BOL_FLD].Value = objObject.BOL;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.CONFIRMPACKDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[SO_PackListMasterTable.CONFIRMPACKDATE_FLD].Value = objObject.ConfirmPackDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.EMPLOYEEID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListMasterTable.EMPLOYEEID_FLD].Value = objObject.EmployeeID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.UNITOFMEASUREID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListMasterTable.UNITOFMEASUREID_FLD].Value = objObject.UnitOfMeasureID;
				
				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to add data to SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///        SO_PackListMasterVO       
		///    </Inputs>
		///    <Outputs>
		///       newly inserted primarkey value
		///    </Outputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************

		public void AddFirstTimePackList(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";
			 
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS =null;
			try
			{
				SO_PackListMasterVO objObject = (SO_PackListMasterVO) pobjObjectVO;
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand("", oconPCS);
				
				strSql=	"INSERT INTO SO_PackListMaster("
					+ SO_PackListMasterTable.PACKLISTNO_FLD + ","
					+ SO_PackListMasterTable.PACKEDDATETIME_FLD
					+ ")"
				+ "VALUES(?,?)";

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.PACKLISTNO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[SO_PackListMasterTable.PACKLISTNO_FLD].Value = objObject.PackListNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.PACKEDDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[SO_PackListMasterTable.PACKEDDATETIME_FLD].Value = objObject.PackedDateTime;

				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to delete data from SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       void
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************

		public void Delete(int pintID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = String.Empty;
			strSql=	"DELETE " + SO_PackListMasterTable.TABLE_NAME + " WHERE  " + "PackListMasterID" + "=" + pintID.ToString();
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get data from SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       SO_PackListMasterVO
		///    </Outputs>
		///    <Returns>
		///       SO_PackListMasterVO
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************

		public object GetObjectVO(int pintID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				strSql=	"SELECT "
				+ SO_PackListMasterTable.PACKLISTMASTERID_FLD + ","
				+ SO_PackListMasterTable.PACKLISTNO_FLD + ","
				+ SO_PackListMasterTable.PACKEDDATETIME_FLD + ","
				+ SO_PackListMasterTable.STATUS_FLD + ","
				+ SO_PackListMasterTable.SHIPPED_FLD + ","
				+ SO_PackListMasterTable.SHIPDATE_FLD + ","
				+ SO_PackListMasterTable.CARRIERID_FLD + ","
				+ SO_PackListMasterTable.WEIGHT_FLD + ","
				+ SO_PackListMasterTable.BOL_FLD + ","
				+ SO_PackListMasterTable.CONFIRMPACKDATE_FLD + ","
				+ SO_PackListMasterTable.EMPLOYEEID_FLD + ","
				+ SO_PackListMasterTable.UNITOFMEASUREID_FLD
				+ " FROM " + SO_PackListMasterTable.TABLE_NAME
				+" WHERE " + SO_PackListMasterTable.PACKLISTMASTERID_FLD + "=" + pintID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				SO_PackListMasterVO objObject = new SO_PackListMasterVO();

				while (odrPCS.Read())
				{ 
					objObject.PackListMasterID = int.Parse(odrPCS[SO_PackListMasterTable.PACKLISTMASTERID_FLD].ToString().Trim());
					objObject.PackListNo = odrPCS[SO_PackListMasterTable.PACKLISTNO_FLD].ToString().Trim();
					objObject.PackedDateTime = DateTime.Parse(odrPCS[SO_PackListMasterTable.PACKEDDATETIME_FLD].ToString().Trim());
					objObject.Status = odrPCS[SO_PackListMasterTable.STATUS_FLD].ToString().Trim();
					try
					{
						objObject.Shipped = bool.Parse(odrPCS[SO_PackListMasterTable.SHIPPED_FLD].ToString().Trim());
					}
					catch
					{
						objObject.Shipped = false;
					}
					if (odrPCS[SO_PackListMasterTable.SHIPDATE_FLD].ToString().Trim() != string.Empty)
					{
						objObject.ShipDate = DateTime.Parse(odrPCS[SO_PackListMasterTable.SHIPDATE_FLD].ToString().Trim());
					}
					if (odrPCS[SO_PackListMasterTable.CARRIERID_FLD].ToString().Trim() != string.Empty)
					{
						objObject.CarrierID = int.Parse(odrPCS[SO_PackListMasterTable.CARRIERID_FLD].ToString().Trim());
					}
					if (odrPCS[SO_PackListMasterTable.WEIGHT_FLD].ToString().Trim() != string.Empty)
					{
						objObject.Weight = Decimal.Parse(odrPCS[SO_PackListMasterTable.WEIGHT_FLD].ToString().Trim());
					}
					objObject.BOL = odrPCS[SO_PackListMasterTable.BOL_FLD].ToString().Trim();
					if (odrPCS[SO_PackListMasterTable.CONFIRMPACKDATE_FLD].ToString().Trim() != string.Empty)
					{
						objObject.ConfirmPackDate = DateTime.Parse(odrPCS[SO_PackListMasterTable.CONFIRMPACKDATE_FLD].ToString().Trim());
					}
					if(odrPCS[SO_PackListMasterTable.EMPLOYEEID_FLD].ToString().Trim() != string.Empty)
					{
						objObject.EmployeeID = int.Parse(odrPCS[SO_PackListMasterTable.EMPLOYEEID_FLD].ToString().Trim());
					}
					if (odrPCS[SO_PackListMasterTable.UNITOFMEASUREID_FLD].ToString().Trim() != string.Empty)
					{
						objObject.UnitOfMeasureID = int.Parse(odrPCS[SO_PackListMasterTable.UNITOFMEASUREID_FLD].ToString().Trim());
					}
				}		
				return objObject;					
			}
			catch(OleDbException ex)
			{			
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get data from SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///        PackListNo    
		///    </Inputs>
		///    <Outputs>
		///       SO_PackListMasterVO
		///    </Outputs>
		///    <Returns>
		///       SO_PackListMasterVO
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************

		public object GetObjectVO(string pstrPackListNo)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				strSql=	"SELECT "
					+ SO_PackListMasterTable.PACKLISTMASTERID_FLD + ","
					+ SO_PackListMasterTable.PACKLISTNO_FLD + ","
					+ SO_PackListMasterTable.PACKEDDATETIME_FLD + ","
					+ SO_PackListMasterTable.STATUS_FLD + ","
					+ SO_PackListMasterTable.SHIPPED_FLD + ","
					+ SO_PackListMasterTable.SHIPDATE_FLD + ","
					+ SO_PackListMasterTable.CARRIERID_FLD + ","
					+ SO_PackListMasterTable.WEIGHT_FLD + ","
					+ SO_PackListMasterTable.BOL_FLD + ","
					+ SO_PackListMasterTable.CONFIRMPACKDATE_FLD + ","
					+ SO_PackListMasterTable.EMPLOYEEID_FLD + ","
					+ SO_PackListMasterTable.UNITOFMEASUREID_FLD
					+ " FROM " + SO_PackListMasterTable.TABLE_NAME
					+" WHERE " + SO_PackListMasterTable.PACKLISTNO_FLD + "= '" + pstrPackListNo +  "'";

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				SO_PackListMasterVO objObject = new SO_PackListMasterVO();
				objObject.PackListMasterID = 0;
				while (odrPCS.Read())
				{ 
					objObject.PackListMasterID = int.Parse(odrPCS[SO_PackListMasterTable.PACKLISTMASTERID_FLD].ToString().Trim());
					objObject.PackListNo = odrPCS[SO_PackListMasterTable.PACKLISTNO_FLD].ToString().Trim();
					objObject.PackedDateTime = DateTime.Parse(odrPCS[SO_PackListMasterTable.PACKEDDATETIME_FLD].ToString().Trim());
					objObject.Status = odrPCS[SO_PackListMasterTable.STATUS_FLD].ToString().Trim();
					try
					{
						objObject.Shipped = bool.Parse(odrPCS[SO_PackListMasterTable.SHIPPED_FLD].ToString().Trim());
					}
					catch
					{
						objObject.Shipped = false;
					}
					if (odrPCS[SO_PackListMasterTable.SHIPDATE_FLD].ToString().Trim() != string.Empty)
					{
						objObject.ShipDate = DateTime.Parse(odrPCS[SO_PackListMasterTable.SHIPDATE_FLD].ToString().Trim());
					}
					if (odrPCS[SO_PackListMasterTable.CARRIERID_FLD].ToString().Trim() != string.Empty)
					{
						objObject.CarrierID = int.Parse(odrPCS[SO_PackListMasterTable.CARRIERID_FLD].ToString().Trim());
					}
					if (odrPCS[SO_PackListMasterTable.WEIGHT_FLD].ToString().Trim() != string.Empty)
					{
						objObject.Weight = Decimal.Parse(odrPCS[SO_PackListMasterTable.WEIGHT_FLD].ToString().Trim());
					}
					objObject.BOL = odrPCS[SO_PackListMasterTable.BOL_FLD].ToString().Trim();
					if (odrPCS[SO_PackListMasterTable.CONFIRMPACKDATE_FLD].ToString().Trim() != string.Empty)
					{
						objObject.ConfirmPackDate = DateTime.Parse(odrPCS[SO_PackListMasterTable.CONFIRMPACKDATE_FLD].ToString().Trim());
					}
					if(odrPCS[SO_PackListMasterTable.EMPLOYEEID_FLD].ToString().Trim() != string.Empty)
					{
						objObject.EmployeeID = int.Parse(odrPCS[SO_PackListMasterTable.EMPLOYEEID_FLD].ToString().Trim());
					}
					if (odrPCS[SO_PackListMasterTable.UNITOFMEASUREID_FLD].ToString().Trim() != string.Empty)
					{
						objObject.UnitOfMeasureID = int.Parse(odrPCS[SO_PackListMasterTable.UNITOFMEASUREID_FLD].ToString().Trim());
					}
				}		
				return objObject;					
			}
			catch(OleDbException ex)
			{			
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to update data to SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///       SO_PackListMasterVO       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void Update(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			SO_PackListMasterVO objObject = (SO_PackListMasterVO) pobjObjecVO;
			

			//prepare value for parameters
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				strSql=	"UPDATE SO_PackListMaster SET "
				+ SO_PackListMasterTable.PACKLISTNO_FLD + "=   ?" + ","
				+ SO_PackListMasterTable.PACKEDDATETIME_FLD + "=   ?" + ","
				+ SO_PackListMasterTable.STATUS_FLD + "=   ?" + ","
				+ SO_PackListMasterTable.SHIPPED_FLD + "=   ?" + ","
				+ SO_PackListMasterTable.SHIPDATE_FLD + "=   ?" + ","
				+ SO_PackListMasterTable.CARRIERID_FLD + "=   ?" + ","
				+ SO_PackListMasterTable.WEIGHT_FLD + "=   ?" + ","
				+ SO_PackListMasterTable.BOL_FLD + "=   ?" + ","
				+ SO_PackListMasterTable.CONFIRMPACKDATE_FLD + "=   ?" + ","
				+ SO_PackListMasterTable.EMPLOYEEID_FLD + "=   ?" + ","
				+ SO_PackListMasterTable.UNITOFMEASUREID_FLD + "=  ?"
				+" WHERE " + SO_PackListMasterTable.PACKLISTMASTERID_FLD + "= ?";

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.PACKLISTNO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[SO_PackListMasterTable.PACKLISTNO_FLD].Value = objObject.PackListNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.PACKEDDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[SO_PackListMasterTable.PACKEDDATETIME_FLD].Value = objObject.PackedDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.STATUS_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[SO_PackListMasterTable.STATUS_FLD].Value = objObject.Status;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.SHIPPED_FLD, OleDbType.Boolean));
				ocmdPCS.Parameters[SO_PackListMasterTable.SHIPPED_FLD].Value = objObject.Shipped;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.SHIPDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[SO_PackListMasterTable.SHIPDATE_FLD].Value = objObject.ShipDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.CARRIERID_FLD, OleDbType.Integer));
				if (objObject.CarrierID > 0)
				{
					ocmdPCS.Parameters[SO_PackListMasterTable.CARRIERID_FLD].Value = objObject.CarrierID;
				}
				else
				{
					ocmdPCS.Parameters[SO_PackListMasterTable.CARRIERID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.WEIGHT_FLD, OleDbType.Decimal));
				if (objObject.Weight >0)
				{
					ocmdPCS.Parameters[SO_PackListMasterTable.WEIGHT_FLD].Value = objObject.Weight;
				}
				else
				{
					ocmdPCS.Parameters[SO_PackListMasterTable.WEIGHT_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.BOL_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[SO_PackListMasterTable.BOL_FLD].Value = objObject.BOL;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.CONFIRMPACKDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[SO_PackListMasterTable.CONFIRMPACKDATE_FLD].Value = objObject.ConfirmPackDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.EMPLOYEEID_FLD, OleDbType.Integer));
				if (objObject.EmployeeID > 0)
				{
					ocmdPCS.Parameters[SO_PackListMasterTable.EMPLOYEEID_FLD].Value = objObject.EmployeeID;
				}
				else
				{
					ocmdPCS.Parameters[SO_PackListMasterTable.EMPLOYEEID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.UNITOFMEASUREID_FLD, OleDbType.Integer));
				if (objObject.UnitOfMeasureID > 0)
				{
					ocmdPCS.Parameters[SO_PackListMasterTable.UNITOFMEASUREID_FLD].Value = objObject.UnitOfMeasureID;
				}
				else
				{
					ocmdPCS.Parameters[SO_PackListMasterTable.UNITOFMEASUREID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.PACKLISTMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListMasterTable.PACKLISTMASTERID_FLD].Value = objObject.PackListMasterID;

				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to update data to SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///       SO_PackListMasterVO       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void UpdateALittle(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			SO_PackListMasterVO objObject = (SO_PackListMasterVO) pobjObjecVO;
			

			//prepare value for parameters
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				strSql=	"UPDATE SO_PackListMaster SET "
					+ SO_PackListMasterTable.PACKLISTNO_FLD + "=   ?" + ","
					+ SO_PackListMasterTable.PACKEDDATETIME_FLD + "=   ?" + ""
					+" WHERE " + SO_PackListMasterTable.PACKLISTMASTERID_FLD + "= ?";

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.PACKLISTNO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[SO_PackListMasterTable.PACKLISTNO_FLD].Value = objObject.PackListNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.PACKEDDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[SO_PackListMasterTable.PACKEDDATETIME_FLD].Value = objObject.PackedDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListMasterTable.PACKLISTMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListMasterTable.PACKLISTMASTERID_FLD].Value = objObject.PackListMasterID;

				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///               
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataSet List()
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				strSql=	"SELECT "
				+ SO_PackListMasterTable.PACKLISTMASTERID_FLD + ","
				+ SO_PackListMasterTable.PACKLISTNO_FLD + ","
				+ SO_PackListMasterTable.PACKEDDATETIME_FLD + ","
				+ SO_PackListMasterTable.STATUS_FLD + ","
				+ SO_PackListMasterTable.SHIPPED_FLD + ","
				+ SO_PackListMasterTable.SHIPDATE_FLD + ","
				+ SO_PackListMasterTable.CARRIERID_FLD + ","
				+ SO_PackListMasterTable.WEIGHT_FLD + ","
				+ SO_PackListMasterTable.BOL_FLD + ","
				+ SO_PackListMasterTable.CONFIRMPACKDATE_FLD + ","
				+ SO_PackListMasterTable.EMPLOYEEID_FLD + ","
				+ SO_PackListMasterTable.UNITOFMEASUREID_FLD
					+ " FROM " + SO_PackListMasterTable.TABLE_NAME;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,SO_PackListMasterTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
   				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       Create conditon string to select Packlistno
		///    </Description>
		///    <Inputs>
		///		  pintType : 0 - Packlistmanagement and ConfirmPacklist
		///					 1 - ConfirmShipment
		///    </Inputs>
		///    <Outputs>
		///    </Outputs>
		///    <Returns>
		///       string
		///    </Returns>
		///    <Authors>
		///       TuanDm
		///    </Authors>
		///    <History>
		///       Friday, February 25, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public static string CreateConditionToSelectPackList(int pintMasterLocID, int pintType)
		{
			string strCondition = string.Empty;
			//case of Pack list management or
			if (pintType ==0)
			{
				strCondition	= " B." + SO_PackListDetailTable.MASTERLOCATIONID_FLD + " = " + pintMasterLocID.ToString() + " and (Status = '' or status is null)";
			}
			if (pintType ==1)
			{
			}
			return strCondition;
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///       pstrParams : Value of parameter
		///       pintType :   0 - SearchToPack, SearchToConfirm, 2 - SearchToConfirmShipment        
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataSet List(int pintMasterLocID, int pintType)
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				strSql=	"SELECT "
					+ "DISTINCT A." + SO_PackListMasterTable.PACKLISTMASTERID_FLD + ","
					+ SO_PackListMasterTable.PACKLISTNO_FLD
					+ " FROM "	+ SO_PackListMasterTable.TABLE_NAME + " A inner join " 
								+ SO_PackListDetailTable.TABLE_NAME + " B on A." + SO_PackListMasterTable.PACKLISTMASTERID_FLD
								+ " = B." + SO_PackListMasterTable.PACKLISTMASTERID_FLD
					+ " WHERE " + CreateConditionToSelectPackList(pintMasterLocID, 0);
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,SO_PackListMasterTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataSet ListAllToShipment(int pintMasterLocationID)
		{
			string strCondition = " B." + SO_PackListDetailTable.MASTERLOCATIONID_FLD + " = " + pintMasterLocationID.ToString() + " and Status = 'ConfirmPacked'";
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				strSql=	"Select Distinct " + SO_PackListMasterTable.PACKLISTNO_FLD 
						+ ", D." + SO_SaleOrderMasterTable.CODE_FLD
						+ ", E." + MST_CarrierTable.NAME_FLD
						+ ", A." + MST_CarrierTable.CARRIERID_FLD
						+ " From " + SO_PackListMasterTable.TABLE_NAME + " A "
						+ " inner join " + SO_PackListDetailTable.TABLE_NAME + " B on A." + SO_PackListDetailTable.PACKLISTMASTERID_FLD + " = B." + SO_PackListDetailTable.PACKLISTMASTERID_FLD
						+ " inner join " + SO_SaleOrderDetailTable.TABLE_NAME+ " C on B." + SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD+" = C." +  SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD 
						+ " inner join " + SO_SaleOrderMasterTable.TABLE_NAME+ " D on C." + SO_SaleOrderDetailTable.SALEORDERMASTERID_FLD+" = D." +	SO_SaleOrderMasterTable.SALEORDERMASTERID_FLD
						+ " inner join " + MST_CarrierTable.TABLE_NAME + " E on A." + MST_CarrierTable.CARRIERID_FLD + " = E." + MST_CarrierTable.CARRIERID_FLD
						+ " Where " + strCondition;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,SO_PackListDetailTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from SO_PackListMaster
		///    </Description>
		///    <Inputs>
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataSet ListPackListMasterToShipment(int pintMasterLocationID)
		{
			string strCondition = " B." + SO_PackListDetailTable.MASTERLOCATIONID_FLD + " = " + pintMasterLocationID.ToString() + " and Status = 'ConfirmPacked'";
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = "Select Distinct " + SO_PackListMasterTable.PACKLISTNO_FLD 
					+ " From " + SO_PackListMasterTable.TABLE_NAME + " A "
					+ " Inner join " + SO_PackListDetailTable.TABLE_NAME + " B on A." + SO_PackListDetailTable.PACKLISTMASTERID_FLD + " = B." + SO_PackListDetailTable.PACKLISTMASTERID_FLD
					+ " Where " + strCondition;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS, SO_PackListMasterTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///    Get all PackListNo and SaleOrder which's confirmshipable
		///    </Description>
		///    <Inputs>
		///    pintMasterLocationID
		///    </Inputs>
		///    <Outputs>
		///    </Outputs>
		///    <Returns>
		///       DataTable
		///    </Returns>
		///    <Authors>
		///       TuanDm
		///    </Authors>
		///    <History>
		///       Friday, Apr 29, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataTable ListConfirmable(int pintMasterLocationID)
		{
			const string METHOD_NAME = THIS + ".ListConfirmable()";
			string strConditionPack = " B." + SO_PackListDetailTable.MASTERLOCATIONID_FLD + " = " + pintMasterLocationID.ToString() + " and Status = 'ConfirmPacked'";
			string strConditionSale = " C." + MST_LocationTable.MASTERLOCATIONID_FLD + " = " + pintMasterLocationID.ToString();
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql =	"Select Distinct " + SO_PackListMasterTable.PACKLISTNO_FLD 
					+ ", D." + SO_SaleOrderMasterTable.CODE_FLD
					+ ", (Select " + MST_CarrierTable.NAME_FLD + " From " + MST_CarrierTable.TABLE_NAME + " Where " + MST_CarrierTable.TABLE_NAME + "." + MST_CarrierTable.CARRIERID_FLD + " = A." + MST_CarrierTable.CARRIERID_FLD + ") as Name "
					+ ", A." + MST_CarrierTable.CARRIERID_FLD
					+ " From " + SO_PackListMasterTable.TABLE_NAME + " A "
					+ " inner join " + SO_PackListDetailTable.TABLE_NAME + " B on A." + SO_PackListDetailTable.PACKLISTMASTERID_FLD + " = B." + SO_PackListDetailTable.PACKLISTMASTERID_FLD
					+ " inner join " + SO_SaleOrderDetailTable.TABLE_NAME+ " C on B." + SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD+" = C." +  SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD 
					+ " inner join " + SO_SaleOrderMasterTable.TABLE_NAME+ " D on C." + SO_SaleOrderDetailTable.SALEORDERMASTERID_FLD+" = D." +	SO_SaleOrderMasterTable.SALEORDERMASTERID_FLD
					+ " Where " + strConditionPack
					+ " Union all "
					+ " Select Distinct '' as " + SO_PackListMasterTable.PACKLISTNO_FLD 
					+ ", A." + SO_SaleOrderMasterTable.CODE_FLD
					+ ", (Select " + MST_CarrierTable.NAME_FLD + " From " + MST_CarrierTable.TABLE_NAME + " Where " + MST_CarrierTable.TABLE_NAME + "." + MST_CarrierTable.CARRIERID_FLD + " = A." + MST_CarrierTable.CARRIERID_FLD + ") as Name "
					+ ", A." + MST_CarrierTable.CARRIERID_FLD
					+ " From " + SO_SaleOrderMasterTable.TABLE_NAME + " A "
					+ " inner join " + MST_MasterLocationTable.TABLE_NAME+ " C on A." + SO_SaleOrderMasterTable.SHIPFROMLOCID_FLD + " = C." + MST_MasterLocationTable.MASTERLOCATIONID_FLD
					+ " Where " + strConditionSale + " and (Select count(*) from "  + SO_CommitInventoryDetailTable.TABLE_NAME + " inner join " 
					+ SO_DeliveryScheduleTable.TABLE_NAME + " on " + SO_CommitInventoryDetailTable.TABLE_NAME + "." + SO_CommitInventoryDetailTable.DELIVERYSCHEDULEID_FLD + " = " + SO_DeliveryScheduleTable.TABLE_NAME + "." + SO_DeliveryScheduleTable.DELIVERYSCHEDULEID_FLD
					+ " Inner join " + SO_SaleOrderDetailTable.TABLE_NAME + " on " + SO_DeliveryScheduleTable.TABLE_NAME + "." + SO_DeliveryScheduleTable.SALEORDERDETAILID_FLD + " = " + SO_SaleOrderDetailTable.TABLE_NAME + "." + SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD 
					+ " Where " + SO_SaleOrderDetailTable.TABLE_NAME + "." + SO_SaleOrderDetailTable.SALEORDERMASTERID_FLD + " = A." + SO_CommitInventoryMasterTable.SALEORDERMASTERID_FLD 
					+ " and ("  + SO_CommitInventoryDetailTable.TABLE_NAME + "." + SO_CommitInventoryDetailTable.SHIPPED_FLD + " is null or " 
					+ SO_CommitInventoryDetailTable.TABLE_NAME + "." + SO_CommitInventoryDetailTable.SHIPPED_FLD + " =0) and ( "
					+ SO_CommitInventoryDetailTable.TABLE_NAME + "." + SO_CommitInventoryDetailTable.PACKED_FLD + " is null or "
					+ SO_CommitInventoryDetailTable.TABLE_NAME + "." + SO_CommitInventoryDetailTable.PACKED_FLD + " =0)) > 0";
					
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS, SO_PackListMasterTable.TABLE_NAME);

				return dstPCS.Tables[0];
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
		
		//**************************************************************************              
		///    <Description>
		///       This method uses to update a DataSet
		///    </Description>
		///    <Inputs>
		///        DataSet       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void UpdateDataSet(DataSet pData)
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";
			string strSql;
			OleDbConnection oconPCS =null;
			OleDbCommandBuilder odcbPCS ;
			OleDbDataAdapter odadPCS = new OleDbDataAdapter();

			try
			{
				strSql=	"SELECT "
				+ SO_PackListMasterTable.PACKLISTMASTERID_FLD + ","
				+ SO_PackListMasterTable.PACKLISTNO_FLD + ","
				+ SO_PackListMasterTable.PACKEDDATETIME_FLD + ","
				+ SO_PackListMasterTable.STATUS_FLD + ","
				+ SO_PackListMasterTable.SHIPPED_FLD + ","
				+ SO_PackListMasterTable.SHIPDATE_FLD + ","
				+ SO_PackListMasterTable.CARRIERID_FLD + ","
				+ SO_PackListMasterTable.WEIGHT_FLD + ","
				+ SO_PackListMasterTable.BOL_FLD + ","
				+ SO_PackListMasterTable.CONFIRMPACKDATE_FLD + ","
				+ SO_PackListMasterTable.EMPLOYEEID_FLD + ","
				+ SO_PackListMasterTable.UNITOFMEASUREID_FLD 
				+ "  FROM " + SO_PackListMasterTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
				odcbPCS = new OleDbCommandBuilder(odadPCS);
				pData.EnforceConstraints = false;
				odadPCS.Update(pData,SO_PackListMasterTable.TABLE_NAME);

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{

					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///			Auto delete all data in the SO_PackListMaster if has no item in SO_PackListDetail
		///    </Description>
		///    <Inputs>
		///    </Inputs>
		///    <Outputs>
		///    </Outputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <Authors>
		///       TuanDm
		///    </Authors>
		///    <History>
		///       Monday, Mar 07, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void AutoDeletePackListMaster()
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";
			string strSql;
			OleDbConnection oconPCS = null;
			try
			{
				strSql =	"Delete " +
					"From " + SO_PackListMasterTable.TABLE_NAME +
					" Where (Select count (*)" +
					" From " + SO_PackListDetailTable.TABLE_NAME +
					" Where "+ SO_PackListDetailTable.TABLE_NAME + "." + SO_PackListDetailTable.PACKLISTMASTERID_FLD   + " = " + SO_PackListMasterTable.TABLE_NAME + "." + SO_PackListMasterTable.PACKLISTMASTERID_FLD + ") = 0";

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				OleDbCommand ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();
				ocmdPCS = null;
			}
			catch (OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
				}

				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
				}
			}

			catch (InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}
	}
}
